﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO

CREATE TABLE [dbo].[bht_UrlsFunctionality](
	[UrlID] [int] NOT NULL,
	[Functionality] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_bht_UrlsFunctionality] PRIMARY KEY CLUSTERED 
(
	[UrlID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[bht_UrlsFunctionality]  WITH CHECK ADD  CONSTRAINT [FK_bht_UrlsFunctionality_mp_FriendlyUrls] FOREIGN KEY([UrlID])
REFERENCES [dbo].[mp_FriendlyUrls] ([UrlID])
GO

ALTER TABLE [dbo].[bht_UrlsFunctionality] CHECK CONSTRAINT [FK_bht_UrlsFunctionality_mp_FriendlyUrls]
GO


CREATE PROCEDURE [dbo].[bhp_FindUrlByFunctionality]
(
	@Function	NVARCHAR(50),
	@SiteId		INT = 1
)
AS
BEGIN

	SELECT
		f.UrlID
	FROM
		mp_FriendlyUrls f
		INNER JOIN bht_UrlsFunctionality uf ON f.UrlID = uf.UrlID
	WHERE
		uf.Functionality = @Function
		AND f.SiteID = @SiteId

END
	